//
//  TuCollectionViewCell.m
//  XRSquare
//
//  Created by 穆相臣 on 2018/8/22.
//  Copyright © 2018年 UaenaMo. All rights reserved.
//

#import "TuCollectionViewCell.h"

@interface TuCollectionViewCell ()
{
    UIImageView * imageContent;
    UIButton * deleteButton;
    UIImageView * addImage;
}
@end

@implementation TuCollectionViewCell

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        imageContent = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth/2, ScreenWidth/2)];
        imageContent.contentMode = UIViewContentModeScaleAspectFill;
        imageContent.clipsToBounds = YES;
        [self addSubview:imageContent];
        
        deleteButton = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/2 - 40, 10, 30, 30)];
        [deleteButton setImage:[UIImage imageNamed:@"delete_fill"] forState:UIControlStateNormal];
        [deleteButton addTarget:self action:@selector(deleteAction) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:deleteButton];
        
        addImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth/4, ScreenWidth/4)];
        addImage.image = [UIImage imageNamed:@"untitled44"];
        addImage.center = CGPointMake(ScreenWidth/4, ScreenWidth/4);
        [self addSubview:addImage];
    }
    return self;
}

-(void)loadData:(NSString *)data
{
    deleteButton.hidden = NO;
    imageContent.hidden = NO;
    addImage.hidden = YES;
    [imageContent sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://pic.xrsquare.com/%@",data]]];
}

-(void)loadAdd
{
    deleteButton.hidden = YES;
    imageContent.hidden = YES;
    addImage.hidden = NO;
}

-(void)deleteAction
{
    [self.delegate deleteIndex:self.imageIndex];
}

@end
